<template>
	<view class="wrap" style="padding-bottom: 60px;">
		<view class="addBtn" @click="addNewe()">+</view>
		<!-- 当前套餐 -->
		
		<view v-if="current === 1">
			<view class="search">
				<u-search v-model="keywords" @custom="search" @search="search"></u-search>
			</view>
			
			<u-card class="task-list-item" :border="false" padding="20" margin="20rpx" v-for="(item,i) in lists" @click="showPho(item)">
				<view slot="head" style="display: flex;align-items: center;justify-content: space-between;">
					<view style="display: flex;align-items: center;" class="u-font-22"><image class="user-images" src="/static/aidex/images/truck.png"></image>{{item.lsh}}</view>
				</view>
				<view class="" slot="body">
					<u-row gutter="16">
						<u-col span="6" style="color: #999999;display: flex;" class="u-font-13">
							
							
							<view style="float: right;">{{$u.timeFormat(item.createtime, 'yyyy年mm月dd日')}}</view>
							<view style="margin-left: 20rpx;">录入者：{{item.nickname}}</view>
						</u-col>
						<u-col span="6" class="u-rela u-row-right" style="text-align:right" v-if="isEdtor==true">
							
							<u-button size="mini" type="warning" :ripple="true" ripple-bg-color="#909399" @click="editNewe(item.id)"  shape="circle" style="margin-right: 10rpx;">
								<u-icon name="edit-pen" size="26" class="u-p-r-8"></u-icon>
								</u-button>
							<u-button size="mini" type="error" :ripple="true" ripple-bg-color="#909399" @click="deleNewe(item)" shape="circle">
								<u-icon name="close-circle" size="26" class="u-p-r-8"></u-icon>
								</u-button>
						</u-col>
					</u-row>
				</view>
			</u-card>
			
		
			
		</view>
			
	</view>
</template>
<script>
export default {
		data() {
			return {
			show: false,
			isEdtor:false,
			list: [{
				name: '发起申请'
			}, {
				name: '查看数据',
			}],
			m2mSimflowList:[],
			m2mOrderFlowList:[],
			current: 1,
			status: 'loadmore',
			iconType: 'circle',
			isDot: false,
			keywords:'',
			loadText: {
						loadmore: '点击加载更多',
						loading: '正在加载...',
						nomore: '没有更多了'
			},
			lists:null
			}
		},
		created(){
			
		},
		onShow() {
			this.getList()
		},
		
			
		methods: {
			change(index) {
				this.current = index;
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			search(value){
				this.$u.api.energy.getLists({
					pageNum: 1,
					pageSize:10,
					lsh:value
				})
				.then(res => {
				
					if (res.code == '200') {
						this.lists=res.rows
					}else{
						this.$u.toast(res.msg);
					}
				}
				);
				
			},
			editNewe(id){
				console.log(id)
				uni.navigateTo({
					url: '/pages/works/newe/edit?id='+id
				});
			},
			showPho(item){
				uni.navigateTo({
					url: '/pages/works/newe/show?id='+item.id
				});
			},	
			onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数	
					this.getUserInfo();		
						this.getList()
			},
			deleNewe(item){
				var self = this;
				uni.showModal({
					title: '提示',
					content: '是否要删除此记录？',
					success: function (res) {
						if (res.confirm) {
						
							
							self.$u.api.energy.delPho({
									id:item.id
								})
								.then(res => {
									let index = self.lists.indexOf(item);
							
									self.lists.splice(index,1)
									if (res.code == '200') {
									self.$u.toast(res.msg);
									}else{
										self.$u.toast(res.msg);
									}
								}
								);
						}
					}
				});			
			},
			getUserInfo() {
				this.userinfo = this.vuex_user
				
				let roles=this.userinfo.roles
				
				for (var i = 0; i < roles.length; i++) {
					if(roles[i].roleName =="超级管理员" || roles[i].roleName =="班长"){
						this.isEdtor=true
					}
				}
				console.log(roles)
			},
			getList(){
				this.$u.api.energy.getLists({
					pageNum: 1,
					pageSize:10
				})
				.then(res => {
				
					if (res.code == '200') {
						this.lists=res.rows
					}else{
						this.$u.toast(res.msg);
					}
				}
				);
			},
			addNewe(){
				uni.navigateTo({
					url: '/pages/works/newe/add'
				});
			}
		}

	}
</script>
<style lang="scss" scoped>
 @import 'index.scss';
page {
	background-color: #f5f5f5;
}
.wrap .search{
	background: #ffffff;
}
.apply-text{
	font-size: 28rpx;
	color: #333333;
	span{
		color: #999999;
	}
}
.user-images{
	width: 28px;
	height:28px;
	margin-right: 8px;
}
.apply-list-foot{
	font-size: 28rpx;
}
.personnel-list{
	display: flex;
	align-items: center;
	flex-wrap:wrap;
	.personnel-user{
		position: relative;
		margin: 5px 9px 0;
	}
	.user-images{
		width: 48px;
		height:48px;
		margin-right:0;
		
	}
	.iconfont{
		position: absolute;
		top:-12px;
		right:-5px;
		color: #FE0100;
	}	
}
	.addBtn{
		z-index: 100;
		position: fixed;
		bottom: 2rem;
		right: 1rem;
		// margin-top: 80%;
		// margin-left: 90%;
		background-color: #2b85e4;
		width: 100rpx;
		height:100rpx;
		border-radius: 50rpx;
		color: #fff;
		font-size: 20px;
		text-align: center;
		font-weight: bold;
		padding: 18rpx;
		box-shadow: 2rpx 4rpx 5rpx #ccc;	
	}

</style>
